package com.sfh.cp.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.sfh.cp.R;

/**
 * 功能描述:
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/3/12
 */
public class WidgetTwoTextLayot extends FrameLayout {
    public WidgetTwoTextLayot(@NonNull Context context) {
        super(context);
        init(null);
    }
    TextView tvLeft;
    TextView tvRight;

    public WidgetTwoTextLayot(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    public WidgetTwoTextLayot(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);init(attrs);
    }

    private void init(@Nullable AttributeSet attrs) {

        LayoutParams lfetP = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lfetP.gravity = Gravity.CENTER | Gravity.LEFT;
        tvLeft = new TextView(this.getContext());
        tvLeft.setLayoutParams(lfetP);

        LayoutParams rightP = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        tvRight = new TextView(this.getContext());
        lfetP.gravity = Gravity.CENTER | Gravity.RIGHT;
        tvRight.setLayoutParams(rightP);

        if (attrs != null){
            TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.WidgetTwoTextLayot);

            int leftSize = array.getDimensionPixelSize(R.styleable.WidgetTwoTextLayot_leftSize,15);
            tvLeft.setTextSize(leftSize);
            int leftColor = array.getColor(R.styleable.WidgetTwoTextLayot_leftColor, Color.BLACK);
            tvLeft.setTextColor(leftColor);
            CharSequence leftText = array.getText(R.styleable.WidgetTwoTextLayot_leftText);
            tvLeft.setText(leftText);

            int rightSize = array.getDimensionPixelSize(R.styleable.WidgetTwoTextLayot_rightSize,15);
            tvRight.setTextSize(rightSize);
            int rightColor = array.getColor(R.styleable.WidgetTwoTextLayot_rightColor, Color.BLACK);
            tvRight.setTextColor(rightColor);
            CharSequence rightHintText = array.getText(R.styleable.WidgetTwoTextLayot_rightHintText);
            tvLeft.setHint(rightHintText);

            array.recycle();
        }

        this.addView(tvLeft);
        this.addView(tvRight);


    }

    public TextView getTvLeft() {
        return tvLeft;
    }

    public TextView getTvRight() {
        return tvRight;
    }
}
